/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package byblos.apresentacao.usuario;

import byblos.negocio.usuario.Usuario;
import java.io.IOException;
import org.vraptor.Interceptor;
import org.vraptor.LogicException;
import org.vraptor.LogicFlow;
import org.vraptor.annotations.In;
import org.vraptor.scope.ScopeType;
import org.vraptor.view.ViewException;

/**
 *
 * @author Diego
 */
public class InterceptadorLogin implements Interceptor {

    @In(scope = ScopeType.SESSION, required = false)
    private Usuario usuario;

    public void intercept(LogicFlow fluxo) throws LogicException, ViewException {
        if (usuario == null) {
            try {
                fluxo.getLogicRequest().getResponse().sendRedirect("/byblos/byblos/usuario/login.jsp");
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } else {
            fluxo.execute();
        }
    }
}
